package com.sogeti.walkthrough.service;

import com.sogeti.walkthrough.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import java.lang.System;


public class AndroidService extends Service {
	private static final int NOTIFICATION_ID=1;
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return new AndroidServiceImpl();
	}
	@Override
	public void onCreate(){
		super.onCreate();
		NotificationManager currentManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		Notification notification = new Notification(R.drawable.icon, "Yo Mama", System.currentTimeMillis());
		
		Context context = getApplicationContext();
		CharSequence contentTitle = getString(R.string.sogeti);
		CharSequence contentText = getString(R.string.startNotification);
		Intent notificationIntent = new Intent(this, AndroidService.class);
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
		
		currentManager.notify(NOTIFICATION_ID, notification);
	}
	public class AndroidServiceImpl extends IAndroidService.Stub{
		public String getAndroidText(String conversation)
				throws RemoteException {
			// TODO Auto-generated method stub
			NotificationManager currentManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
			Notification notification = new Notification(R.drawable.icon, "New Message", System.currentTimeMillis());
			Context context = getApplicationContext();
			CharSequence contentTitle = getString(R.string.sogeti);
			CharSequence contentText = getString(R.string.notificationMessage)+" "+conversation;
			Intent notificationIntent = new Intent(AndroidService.this, AndroidService.class);
			PendingIntent contentIntent = PendingIntent.getActivity(AndroidService.this, 0, notificationIntent, 0);
			notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
			
			currentManager.notify(NOTIFICATION_ID, notification);
			return "Android Services are Fun!";
		}
	}
}
